﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;

namespace SharpSoft.Geometries.Shapes
{
    /// <summary>
    /// 变换接口
    /// </summary>
    public interface ITransform
    {
    }
    /// <summary>
    /// 旋转变换
    /// </summary>
    public struct RotateTransform : ITransform
    {
        public RotateTransform(Radian angle, Point2D center)
        {
            this.Angle = angle;
            this.Center = center;
        }
        public RotateTransform(Radian angle) : this(angle, new Point2D(0, 0))
        {

        }
        /// <summary>
        /// 旋转角度
        /// </summary>
        public Radian Angle { get; set; }
        /// <summary>
        /// 旋转中心
        /// </summary>
        public Point2D Center { get; set; }
    }
    /// <summary>
    /// 缩放变换
    /// </summary>
    public struct ScaleTransform : ITransform
    {
        public ScaleTransform(double scale, Point2D center)
        {
            this.Scale = scale;
            this.Center = center;
        }
        public ScaleTransform(double scale) : this(scale, new Point2D(0, 0))
        {

        }
        /// <summary>
        /// 缩放比例
        /// </summary>
        public double Scale { get; set; }
        /// <summary>
        /// 缩放中心
        /// </summary>
        public Point2D Center { get; set; }
    }
    /// <summary>
    /// 平移变换
    /// </summary>
    public struct TranslateTransform : ITransform
    {
        public TranslateTransform(double ox, double oy)
        {
            this.OffsetX = ox;
            this.OffsetY = oy;
        }
        public double OffsetX { get; set; }
        public double OffsetY { get; set; }
    }
    /// <summary>
    /// 变换队列
    /// </summary>
    public class TransformGroup : IEnumerable<ITransform>, ITransform
    {
        List<ITransform> list = new List<ITransform>();
        public TransformGroup()
        {

        }
        /// <summary>
        /// 添加变换
        /// </summary>
        /// <param name="transform"></param>
        public void Push(ITransform transform)
        {
            list.Add(transform);
        }

        public void PushRotate(Radian radian, Point2D center)
        {
            Push(new RotateTransform(radian, center));
        }

        public void PushScale(double scale, Point2D center)
        {
            Push(new ScaleTransform(scale, center));
        }
        public void PushTransform(double ox, double oy)
        {
            Push(new TranslateTransform(ox, oy));
        }

        public IEnumerator<ITransform> GetEnumerator()
        {
            return list.GetEnumerator();
        }

        IEnumerator IEnumerable.GetEnumerator()
        {
            return list.GetEnumerator();
        }
    }
}
